/*
 * All rights Reserved, Designed By DataDriver
 * Copyright:    DataDriver.Inc
 * Company:      Zhuo Wo Infomation Technology (ShangHai) CO.LTD
 */
package com.sun.unsafe;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;

public class MapTest {


    /**
     * ConcurrentModificationException并发修改异常
     *
     * 1、Collections.synchronizedMap(new HashMap<>()) 解决
     *
     * @param args
     *
     * ConcurrentHashMap原理：
     */


    public static void main(String[] args) {
        //初始容量16，加载因子0.75
        //Map<String,String> map = new HashMap<String,String>(16,0.75f);

       // Map<String, String> map = Collections.synchronizedMap(new HashMap<>());

        Map<String,String> map = new ConcurrentHashMap<>();

        for (int i = 0; i < 30; i++) {
             new Thread(()->{
                 map.put(Thread.currentThread().getName(), UUID.randomUUID().toString().substring(0,6));
                 System.out.println(map);
             }).start();
        }
    }
}
